using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;

namespace CSSg2Help
{
    [Flags]
    public enum MouseEventFlags
    {
        LEFTDOWN   = 0x00000002,
        LEFTUP     = 0x00000004,
        MIDDLEDOWN = 0x00000020,
        MIDDLEUP   = 0x00000040,
        MOVE       = 0x00000001,
        ABSOLUTE   = 0x00008000,
        RIGHTDOWN  = 0x00000008,
        RIGHTUP    = 0x00000010
    }
    public class MouseEvent
    {
        public static int screenX = Screen.PrimaryScreen.Bounds.Right;
        public static int screenY = Screen.PrimaryScreen.Bounds.Bottom;

        [DllImport("user32.dll")]
        public static extern bool SetCursorPos(int x, int y);
        [DllImport("user32.dll")]
        static extern void mouse_event(MouseEventFlags flag, int x, int y, uint data, UIntPtr ptr);

        public static void mouse_event(MouseEventFlags flag, int x, int y)
        {
            mouse_event(flag, x * 65536 / screenX, y * 65536 / screenY, 0, UIntPtr.Zero);
        }
        public static void mouse_click(int x, int y)
        {
            mouse_event(MouseEventFlags.ABSOLUTE | MouseEventFlags.MOVE, x, y);
            mouse_event(MouseEventFlags.ABSOLUTE | MouseEventFlags.LEFTDOWN, x, y);
            mouse_event(MouseEventFlags.ABSOLUTE | MouseEventFlags.LEFTUP, x, y);
        }
    }
}
